package com.crm.system.service.impl.systemManager;

import com.crm.common.util.CommonUtils;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.entity.systemManager.SysParameterSetting;
import com.crm.service.systemManager.ParameterSettingDbService;
import com.crm.system.service.systemManager.ParameterSettingService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Objects;

/**
 * @Author:chaifuyou
 * @Date: 2021/4/21 10:10
 */
@Service
public class ParameterSettingServiceImpl implements ParameterSettingService {

    @Autowired
    private ParameterSettingDbService parameterSettingDbService;

    /**
     * 新增/更改系统设置
     * @param sysParameterSetting
     */
    @Override
    public void systemParameterSetting(SysParameterSetting sysParameterSetting) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        if (Objects.isNull(sysParameterSetting.getSysParameterId()) || "".equals(sysParameterSetting.getSysParameterId())){
            sysParameterSetting.setCreatePeopleId(userAccount.getAccountId());
            sysParameterSetting.setCreateTm(new Date());
            sysParameterSetting.setSysParameterId(CommonUtils.getGUID());
            parameterSettingDbService.addSystemParameterSetting(sysParameterSetting);
        }else {
            sysParameterSetting.setUpdatePeopleId(userAccount.getAccountId());
            sysParameterSetting.setUpdateTm(new Date());
            parameterSettingDbService.updateSystemParameterSetting(sysParameterSetting);
        }
    }

    /**
     * 查询系统设置
     * @return
     */
    @Override
    public SysParameterSetting selectSystemParameterSetting() {
        return parameterSettingDbService.selectSystemParameterSetting();
    }
}
